package gt.edu.usac.viewcontroller.backing.app;

import gt.edu.usac.model.am.AppModuleImpl;

import gt.edu.usac.model.vo.centroViewImpl;
import gt.edu.usac.model.vo.edificioViewImpl;
import gt.edu.usac.model.vo.salonViewImpl;

import javax.faces.application.FacesMessage;
import javax.faces.component.UISelectItems;
import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlPanelGroup;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.event.ActionEvent;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCDataControl;
import oracle.adf.view.faces.component.core.input.CoreInputText;
import oracle.adf.view.faces.component.core.input.CoreSelectOneChoice;
import oracle.adf.view.faces.component.core.layout.CorePanelForm;
import oracle.adf.view.faces.component.core.layout.CorePanelGroup;
import oracle.adf.view.faces.component.core.layout.CorePanelHeader;
import oracle.adf.view.faces.component.core.nav.CoreCommandButton;
import oracle.adf.view.faces.component.core.nav.CoreCommandMenuItem;
import oracle.adf.view.faces.component.core.nav.CorePage;
import oracle.adf.view.faces.component.core.output.CoreMessages;
import oracle.adf.view.faces.component.core.output.CoreObjectImage;
import oracle.adf.view.faces.component.core.output.CoreObjectSpacer;
import oracle.adf.view.faces.component.core.output.CoreOutputFormatted;
import oracle.adf.view.faces.component.core.output.CoreOutputText;
import oracle.adf.view.faces.component.html.HtmlBody;
import oracle.adf.view.faces.component.html.HtmlHead;
import oracle.adf.view.faces.component.html.HtmlHtml;

import oracle.jbo.ApplicationModule;
import oracle.jbo.AttributeList;
import oracle.jbo.Row;
import oracle.jbo.server.AttributeListImpl;

public class CrearSalon {
    private HtmlForm form1;
    private CoreObjectSpacer os4;
    private CoreOutputFormatted outputFormatted3;
    private CoreObjectSpacer os3;
    private CoreOutputFormatted outputFormatted2;
    private CoreOutputText outputText6;
    private CoreObjectSpacer os1;
    private CoreOutputFormatted outputFormatted1;
    private CoreObjectSpacer os2;
    private CoreOutputText outputText5;
    private HtmlPanelGroup panelGroup1;
    private HtmlOutputText outputText1;
    private CoreCommandMenuItem commandMenuItem2;
    private CoreObjectImage objectImage1;
    private CorePage page1;
    private CoreMessages messages1;
    private HtmlBody body1;
    private HtmlHead head1;
    private HtmlHtml html1;
    private CorePanelGroup panelGroup2;
    private CoreSelectOneChoice navList1;
    private UISelectItems selectItems1;
    private CorePanelHeader panelHeader1;
    private CorePanelGroup panelGroup3;
    private CoreSelectOneChoice navList2;
    private UISelectItems selectItems2;
    private CorePanelHeader panelHeader2;
    private CorePanelForm panelForm1;
    private CoreInputText inputText1;
    private CoreInputText inputText2;
    private CoreInputText inputText3;
    private CoreCommandButton commandButton1;
    private CoreCommandButton commandButton2;
    private CorePanelHeader panelHeader3;

    public void setForm1(HtmlForm form1) {
        this.form1 = form1;
    }

    public HtmlForm getForm1() {
        return form1;
    }


    public void guardar(ActionEvent actionEvent) {
        FacesContext ctx = FacesContext.getCurrentInstance();
        
        //Creando el binding container 
        ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
        BindingContext bc = (BindingContext)vb.getValue(ctx);
        
        DCDataControl dc  = bc.findDataControl("AppModuleDataControl");
        ApplicationModule am = (ApplicationModule)dc.getDataProvider();
        AppModuleImpl service    = (AppModuleImpl)am;
        salonViewImpl salon = service.getsalonView2();
        edificioViewImpl edificio = service.getedificioView2();
        centroViewImpl centro = service.getcentroView1();
        FacesMessage msg = null;
        String errores = "";
        try {
            AttributeList salonAtt = new AttributeListImpl();
            if(centro.getCurrentRow()==null){
                errores += "No se ha ingresado centro";
                throw new Exception("No se ha ingresado centro");
            }
            if(edificio.getCurrentRow()==null){
                errores += "No se ha ingresado edificio";
                throw new Exception("No se ha ingresado edificio");
            }
            salonAtt.setAttribute("IdCentro",centro.getCurrentRow().getAttribute("IdCentro"));
            salonAtt.setAttribute("IdEdificio",edificio.getCurrentRow().getAttribute("IdEdificio"));
            if(inputText1.getValue()==null||inputText1.getValue().toString()==""){
                errores += "No se ha ingresado descripcion";
                throw new Exception("No se ha ingresado descripcion");
            }else{
                salonAtt.setAttribute("Descripcion",inputText1.getValue().toString());
            }
            salonAtt.setAttribute("Capacidad",inputText2.getValue().toString());
            salonAtt.setAttribute("CodUnidad",inputText3.getValue().toString());
            
            inputText1.setValue(""); inputText2.setValue(""); inputText3.setValue("");
            Row salonRow = salon.createAndInitRow(salonAtt);
            service.getDBTransaction().commit();
            msg = new FacesMessage("Salon ingresado");
            msg.setSeverity(FacesMessage.SEVERITY_INFO);
        }
        catch (Exception e) {
            msg = new FacesMessage("No se pudo ingresar el salon: "+errores);
            msg.setSeverity(FacesMessage.SEVERITY_ERROR);
        }
        FacesContext.getCurrentInstance().addMessage(null,msg);
    }

    public void setOs4(CoreObjectSpacer os4) {
        this.os4 = os4;
    }

    public CoreObjectSpacer getOs4() {
        return os4;
    }

    public void setOutputFormatted3(CoreOutputFormatted outputFormatted3) {
        this.outputFormatted3 = outputFormatted3;
    }

    public CoreOutputFormatted getOutputFormatted3() {
        return outputFormatted3;
    }

    public void setOs3(CoreObjectSpacer os3) {
        this.os3 = os3;
    }

    public CoreObjectSpacer getOs3() {
        return os3;
    }

    public void setOutputFormatted2(CoreOutputFormatted outputFormatted2) {
        this.outputFormatted2 = outputFormatted2;
    }

    public CoreOutputFormatted getOutputFormatted2() {
        return outputFormatted2;
    }

    public void setOutputText6(CoreOutputText outputText6) {
        this.outputText6 = outputText6;
    }

    public CoreOutputText getOutputText6() {
        return outputText6;
    }

    public void setOs1(CoreObjectSpacer os1) {
        this.os1 = os1;
    }

    public CoreObjectSpacer getOs1() {
        return os1;
    }

    public void setOutputFormatted1(CoreOutputFormatted outputFormatted1) {
        this.outputFormatted1 = outputFormatted1;
    }

    public CoreOutputFormatted getOutputFormatted1() {
        return outputFormatted1;
    }

    public void setOs2(CoreObjectSpacer os2) {
        this.os2 = os2;
    }

    public CoreObjectSpacer getOs2() {
        return os2;
    }

    public void setOutputText5(CoreOutputText outputText5) {
        this.outputText5 = outputText5;
    }

    public CoreOutputText getOutputText5() {
        return outputText5;
    }

    public void setPanelGroup1(HtmlPanelGroup panelGroup1) {
        this.panelGroup1 = panelGroup1;
    }

    public HtmlPanelGroup getPanelGroup1() {
        return panelGroup1;
    }

    public void setOutputText1(HtmlOutputText outputText1) {
        this.outputText1 = outputText1;
    }

    public HtmlOutputText getOutputText1() {
        return outputText1;
    }

    public void setCommandMenuItem2(CoreCommandMenuItem commandMenuItem2) {
        this.commandMenuItem2 = commandMenuItem2;
    }

    public CoreCommandMenuItem getCommandMenuItem2() {
        return commandMenuItem2;
    }

    public void setObjectImage1(CoreObjectImage objectImage1) {
        this.objectImage1 = objectImage1;
    }

    public CoreObjectImage getObjectImage1() {
        return objectImage1;
    }

    public void setPage1(CorePage page1) {
        this.page1 = page1;
    }

    public CorePage getPage1() {
        return page1;
    }

    public void setMessages1(CoreMessages messages1) {
        this.messages1 = messages1;
    }

    public CoreMessages getMessages1() {
        return messages1;
    }

    public void setBody1(HtmlBody body1) {
        this.body1 = body1;
    }

    public HtmlBody getBody1() {
        return body1;
    }

    public void setHead1(HtmlHead head1) {
        this.head1 = head1;
    }

    public HtmlHead getHead1() {
        return head1;
    }

    public void setHtml1(HtmlHtml html1) {
        this.html1 = html1;
    }

    public HtmlHtml getHtml1() {
        return html1;
    }

    public void setPanelGroup2(CorePanelGroup panelGroup2) {
        this.panelGroup2 = panelGroup2;
    }

    public CorePanelGroup getPanelGroup2() {
        return panelGroup2;
    }

    public void setNavList1(CoreSelectOneChoice navList1) {
        this.navList1 = navList1;
    }

    public CoreSelectOneChoice getNavList1() {
        return navList1;
    }

    public void setSelectItems1(UISelectItems selectItems1) {
        this.selectItems1 = selectItems1;
    }

    public UISelectItems getSelectItems1() {
        return selectItems1;
    }

    public void setPanelHeader1(CorePanelHeader panelHeader1) {
        this.panelHeader1 = panelHeader1;
    }

    public CorePanelHeader getPanelHeader1() {
        return panelHeader1;
    }

    public void setPanelGroup3(CorePanelGroup panelGroup3) {
        this.panelGroup3 = panelGroup3;
    }

    public CorePanelGroup getPanelGroup3() {
        return panelGroup3;
    }

    public void setNavList2(CoreSelectOneChoice navList2) {
        this.navList2 = navList2;
    }

    public CoreSelectOneChoice getNavList2() {
        return navList2;
    }

    public void setSelectItems2(UISelectItems selectItems2) {
        this.selectItems2 = selectItems2;
    }

    public UISelectItems getSelectItems2() {
        return selectItems2;
    }

    public void setPanelHeader2(CorePanelHeader panelHeader2) {
        this.panelHeader2 = panelHeader2;
    }

    public CorePanelHeader getPanelHeader2() {
        return panelHeader2;
    }

    public void setPanelForm1(CorePanelForm panelForm1) {
        this.panelForm1 = panelForm1;
    }

    public CorePanelForm getPanelForm1() {
        return panelForm1;
    }

    public void setInputText1(CoreInputText inputText1) {
        this.inputText1 = inputText1;
    }

    public CoreInputText getInputText1() {
        return inputText1;
    }

    public void setInputText2(CoreInputText inputText2) {
        this.inputText2 = inputText2;
    }

    public CoreInputText getInputText2() {
        return inputText2;
    }

    public void setInputText3(CoreInputText inputText3) {
        this.inputText3 = inputText3;
    }

    public CoreInputText getInputText3() {
        return inputText3;
    }


    public void setCommandButton1(CoreCommandButton commandButton1) {
        this.commandButton1 = commandButton1;
    }

    public CoreCommandButton getCommandButton1() {
        return commandButton1;
    }

    public void setCommandButton2(CoreCommandButton commandButton2) {
        this.commandButton2 = commandButton2;
    }

    public CoreCommandButton getCommandButton2() {
        return commandButton2;
    }

    public void setPanelHeader3(CorePanelHeader panelHeader3) {
        this.panelHeader3 = panelHeader3;
    }

    public CorePanelHeader getPanelHeader3() {
        return panelHeader3;
    }
}
